{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3ddd73e0-20e6-43c1-82a2-7c7b66f0d26b",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请指定运算符//\n",
      "请指定下限1\n",
      "请指定上限182\n",
      "42//113=?0\n",
      "答对啦！\n",
      "166//47=?3\n",
      "答对啦！\n",
      "169//29=?7\n",
      "答错啦！\n",
      "继续答题吗？(y/n)y\n",
      "30//27=?1\n",
      "答对啦！\n",
      "138//131=?1\n",
      "答对啦！\n",
      "50//46=?1\n",
      "答对啦！\n",
      "68//101=?0\n",
      "答对啦！\n",
      "97//178=?1\n",
      "答错啦！\n",
      "继续答题吗？(y/n)n\n",
      "答题结束！你的分数是6\n"
     ]
    }
   ],
   "source": [
    "score=0\n",
    "i=1\n",
    "from random import randint\n",
    "oprt=input(\"请指定运算符\")\n",
    "bottom=int(input(\"请指定下限\"))\n",
    "top=int(input(\"请指定上限\"))\n",
    "while i<2:\n",
    "    a=randint(bottom,top)\n",
    "    b=randint(bottom,top)\n",
    "    astr=str(a)\n",
    "    bstr=str(b)\n",
    "    usasw=int(input(astr+oprt+bstr+\"=?\"))\n",
    "    answer=eval(\"a {0} b\".format(oprt))\n",
    "    if usasw==answer:\n",
    "        print(\"答对啦！\")\n",
    "        score=score+1\n",
    "    else:\n",
    "        print(\"答错啦！\")\n",
    "        choice=input(\"继续答题吗？(y/n)\")\n",
    "        if choice==\"n\":\n",
    "            ++i\n",
    "            break\n",
    "print (\"答题结束！你的分数是%d\"%(score))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a6d3f775-fd9c-494c-8197-589a9a774484",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
